
use std::io;

fn main() {
    println!("Hello, world!");

    let flag = true;

    if flag {
        println!("true");
    } else {
        println!("false");
    }

    let number = 100;

    // if number {
    //     println!("number: {number}");
    // }

    if number % 5 == 0 {
        println!("number: {number}");
    } else if number % 4 == 0 {
        println!("number: {number}");
    } else if number % 3 == 0 {
        println!("number: {number}");
    } else {
        println!("number: {number}");
    }

    let mut temp = String::new();

    println!("celsius(0) or fahrenheit(1): ");
    io::stdin().read_line(&mut temp)
               .expect("Failed to read line");

    let is_celsius: bool = temp.trim().parse().expect("not a bool"); 
    if is_celsius {
        println!("Please input celsius: ");

        let mut temp = String::new();
        io::stdin().read_line(&mut temp)
                .expect("Failed to read line");
        
        let celsius: f32 = temp.trim().parse().expect("not a float"); 

        let fahrenheit  = celsius_to_fahrenheit(celsius);
        println!("{celsius}C -> {fahrenheit}F");
    } else {
        println!("Please input fahrenheit: ");

        let mut temp = String::new();
        io::stdin().read_line(&mut temp)
                .expect("Failed to read line");
        
        let fahrenheit: f32 = temp.trim().parse().expect("not a float"); 

        let celsius  = fahrenheit_to_celsius(fahrenheit);
        println!("{fahrenheit}F -> {celsius}C");
    }
}

fn celsius_to_fahrenheit(c:f32) -> f32 {
    return c * (9.0/5.0) + 32.0;
}

fn fahrenheit_to_celsius(f:f32) -> f32 {
    return (f - 32.0) * (5.0/9.0);
}